//
//  BAIHEViewController.m
//  BaiheAdSDK
//
//  Created by 二跳 on 04/13/2025.
//  Copyright (c) 2025 二跳. All rights reserved.
//

#import "BAIHEViewController.h"
#import <BaiheAdSDK/BaiheAdSDKNativeAd.h>
#import <BaiheAdSDK/BaiheAdSDKNativeExpressAd.h>
#import <BaiheAdSDK/BaiheAdSDKSplashAd.h>
#import <BaiheAdSDK/BaiheAdSDKInterstitialAd.h>
#import <BaiheAdSDK/BaiheAdSDKServiceAdView.h>
#import <BaiheAdSDK/BaiheAdSDKBannerAdView.h>
#import <BaiheAdSDK/BaiheAdSDKRewardVideoAd.h>

@interface BAIHEViewController ()<BaiheAdSDKNativeExpressAdDelegate,BaiheAdSDKInterstitialAdDelegate,BaiheAdSDKBannerAdViewDelegate,BaiheAdSDKRewardVideoAdDelegate,BaiheSDKServiceAdViewDelegate>

@property (nonatomic, strong) BaiheAdSDKNativeExpressAd *nativeExpressAd;

@property (nonatomic, strong) BaiheAdSDKInterstitialAd *interstitialAd;

@property (nonatomic, strong) BaiheAdSDKBannerAdView *bannerView;

@property (nonatomic, strong) BaiheAdSDKRewardVideoAd *rewardVideoAd;

@property (nonatomic, strong) BaiheAdSDKServiceAdView *serviceAdView;

@end

@implementation BAIHEViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - 服务广告
- (void)loadServiceAdView{
    self.serviceAdView = [[BaiheAdSDKServiceAdView alloc]initWithFrame:CGRectMake(0, 200, 50, 50)];
    self.serviceAdView.delegate = self;
    self.serviceAdView.controller = self;
    self.serviceAdView.posId = @"";
    // 设置展示关闭按钮
    self.serviceAdView.showCloseView = YES;
    [self.serviceAdView loadAndShow];
}

#pragma mark - BaiheAdSDKServiceAdViewDelegate
/**
 广告获取成功
 
 @param serviceAdView banner实例
 */
- (void)Baihe_serviceAdViewDidReceived:(BaiheAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告拉取失败
 
 @param serviceAdView banner实例
 @param error 错误描述
 */
- (void)Baihe_serviceAdViewFailToReceived:(BaiheAdSDKServiceAdView *)serviceAdView error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 广告点击
 
 @param serviceAdView 广告实例
 @param loadingPageURL 广告落地页地址，当渠道为bwt，并且customLoadingPage为YES时有值
 */
- (void)Baihe_serviceAdViewClicked:(BaiheAdSDKServiceAdView *)serviceAdView loadingPageURL:(NSString *)loadingPageURL{
    NSLog(@"%s", __func__);
}

/**
 广告关闭
 
 @param serviceAdView 广告实例
 */
- (void)Baihe_serviceAdViewClose:(BaiheAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示
 
 @param serviceAdView 广告实例
 */
- (void)Baihe_serviceAdViewExposure:(BaiheAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示上报
 
 @param serviceAdView 广告实例
 */
- (void)Baihe_serviceAdViewExposureReport:(BaiheAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告点击上报
 
 @param serviceAdView 广告实例
 */
- (void)Baihe_serviceAdViewClickedReport:(BaiheAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 关闭落地页
 
 @param serviceAdView 广告实例
 */
- (void)Baihe_serviceAdViewCloseLandingPage:(BaiheAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

#pragma mark - 激励视频广告
- (void)loadRewardVideo{
    self.rewardVideoAd = [[BaiheAdSDKRewardVideoAd alloc]init];
    self.rewardVideoAd.delegate = self;
    self.rewardVideoAd.controller = self;
    self.rewardVideoAd.posId = @"23636003";
    self.rewardVideoAd.videoMuted = YES;
    [self.rewardVideoAd loadRewardVideoAd];
}

#pragma mark - BaiheAdSDKRewardVideoAdDelegate
/**
 广告数据加载成功回调

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdDidLoad:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
    // 价格上报
//    NSInteger price = [self.rewardVideoAd getBidPrice];
//    [self.rewardVideoAd sendWinNotice:price];
    [self.rewardVideoAd showRewardVideoAdFromRootViewController:self];
}

/**
 视频播放页即将展示回调

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdWillVisible:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告曝光回调

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdDidExposed:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告曝光上报回调（只会回调一次）

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdDidExposeReport:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频播放页关闭回调

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdDidClose:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告信息点击回调（可能回调多次）

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdDidClicked:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告信息点击上报回调（只会回调一次）

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdDidClickReport:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告各种错误信息回调

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 @param error 具体错误信息
 */
- (void)Baihe_rewardVideoAd:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd didFailWithError:(NSError *)error{
    NSLog(@"%s", __func__);
}


/**
 视频广告播放达到激励条件回调

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdDidRewardEffective:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告视频播放完成

 @param rewardedVideoAd BaiheAdSDKRewardVideoAd 实例
 */
- (void)Baihe_rewardVideoAdDidPlayFinish:(BaiheAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

#pragma mark - banner广告
- (void)loadBanner{
    CGFloat width = self.view.frame.size.width;
    CGFloat height = width * 5 / 32;
    self.bannerView = [[BaiheAdSDKBannerAdView alloc]initWithFrame:CGRectMake(0, 200, width, height)];
    self.bannerView.delegate = self;
    self.bannerView.controller = self;
    self.bannerView.posId = @"";
    // 设置展示关闭按钮
    self.bannerView.showCloseView = YES;
    [self.bannerView loadAndShow];
}

#pragma mark - BaiheAdSDKBannerAdViewDelegate
/**
 广告获取成功
 
 @param bannerAdView banner实例
 */
- (void)Baihe_bannerAdViewDidReceived:(BaiheAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
    // 价格上报
//    NSInteger price = [self.bannerView getBidPrice];
//    [self.bannerView sendWinNotice:price];
}

/**
 广告拉取失败
 
 @param bannerAdView banner实例
 @param error 错误描述
 */
- (void)Baihe_bannerAdViewFailToReceived:(BaiheAdSDKBannerAdView *)bannerAdView error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 广告点击
 
 @param bannerAdView 广告实例
 */
- (void)Baihe_bannerAdViewClicked:(BaiheAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告关闭
 
 @param bannerAdView 广告实例
 */
- (void)Baihe_bannerAdViewClose:(BaiheAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示
 
 @param bannerAdView 广告实例
 */
- (void)Baihe_bannerAdViewExposure:(BaiheAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示上报
 
 @param bannerAdView 广告实例
 */
- (void)Baihe_bannerAdViewExposureReport:(BaiheAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告点击上报
 
 @param bannerAdView 广告实例
 */
- (void)Baihe_bannerAdViewClickedReport:(BaiheAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 关闭落地页
 
 @param bannerAdView 广告实例
 */
- (void)Baihe_bannerAdViewCloseLandingPage:(BaiheAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

#pragma mark - 插屏广告
- (void)loadInterstitialAd {
    self.interstitialAd = [[BaiheAdSDKInterstitialAd alloc]init];
    self.interstitialAd.delegate = self;
    self.interstitialAd.controller = self;
    self.interstitialAd.posId = @"13945365";
    [self.interstitialAd loadInterstitialAd];
}

#pragma mark - BaiheAdSDKInterstitialAdDelegate
/**
 BaiheAdSDKInterstitialAd请求成功回调
 
 @param interstitialAd 插屏广告实例对象
*/
- (void)Baihe_interstitialAdSuccedToLoad:(BaiheAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
    // 获取价格，价格上报
//    NSInteger price = [self.interstitialAd getBidPrice];
//    [self.interstitialAd sendWinNotice:price];
    // 设置控制器，展示插屏广告
    self.interstitialAd.controller = self;
    [self.interstitialAd showInterstitialAd];
}

/**
 BaiheAdSDKInterstitialAd请求失败回调

 @param interstitialAd 插屏广告实例对象
 @param error 失败原因
*/
- (void)Baihe_interstitialAdFailedToLoad:(BaiheAdSDKInterstitialAd *)interstitialAd error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 BaiheAdSDKInterstitialAd展示在屏幕内回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)Baihe_interstitialAdDidPresent:(BaiheAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 BaiheAdSDKInterstitialAd展示在屏幕内失败回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)Baihe_interstitialAdFailedToPresent:(BaiheAdSDKInterstitialAd *)interstitialAd error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 BaiheAdSDKInterstitialAd点击回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)Baihe_interstitialAdDidClick:(BaiheAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 BaiheAdSDKInterstitialAd关闭回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)Baihe_interstitialAdDidClose:(BaiheAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 BaiheAdSDKInterstitialAd展示回调
 
 @param interstitialAd 广告实例
 */
- (void)Baihe_interstitialAdExposure:(BaiheAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 BaiheAdSDKInterstitialAd展示上报回调
 
 @param interstitialAd 广告实例
 */
- (void)Baihe_interstitialAdExposureReport:(BaiheAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}


/**
 BaiheAdSDKInterstitialAd点击上报回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)Baihe_interstitialAdDidClickReport:(BaiheAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 BaiheAdSDKInterstitialAd关闭落地页回调
 
 @param interstitialAd 广告实例
 */
- (void)Baihe_interstitialAdCloseLandingPage:(BaiheAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}
#pragma mark - 信息流模板广告

- (void)loadNativeExpress {
    CGFloat width = self.view.frame.size.width;
    self.nativeExpressAd = [[BaiheAdSDKNativeExpressAd alloc]initWithAdSize:CGSizeMake(width, 50)];
    self.nativeExpressAd.posId = @"99908725";
    self.nativeExpressAd.delegate = self;
    self.nativeExpressAd.expressType = BaiheNativeExpressTypeImage;
    self.nativeExpressAd.controller = self;
    [self.nativeExpressAd loadNativeExpressAd:1];
}

#pragma mark - BaiheAdSDKNativeExpressAdDelegate
/**
 信息流模版广告请求成功
 
 @param nativeExpressAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)Baihe_nativeExpressAdSucessToLoad:(BaiheAdSDKNativeExpressAd *)nativeExpressAd
                     adViewArray:(NSArray<__kindof UIView<BaiheAdSDKNativeExpressAdViewDelegate> *> *)adViewArray{
    NSLog(@"%s", __func__);
    UIView<BaiheAdSDKNativeExpressAdViewDelegate> *adView = [adViewArray firstObject];
    [adView render];
    [self.view addSubview:adView];
    CGSize adViewSize = adView.frame.size;
    adView.frame = CGRectMake(0, 200, adViewSize.width, adViewSize.height);
}

/**
 信息流模版广告请求失败
 
 @param nativeExpressAd 广告实例
 @param error 请求错误描述
 */
- (void)Baihe_nativeExpressAdFailToLoad:(BaiheAdSDKNativeExpressAd *)nativeExpressAd
                         error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告渲染成功
 
 @param adView 广告视图
 */
- (void)Baihe_nativeExpressAdViewRenderOrRegistSuccess:(UIView<BaiheAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告渲染失败
 
 @param adView 广告视图
 */
- (void)Baihe_nativeExpressAdViewRenderOrRegistFail:(UIView<BaiheAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被点击
 
 @param nativeExpressAd 广告模板
 */
- (void)Baihe_nativeExpressAdClicked:(BaiheAdSDKNativeExpressAd *)nativeExpressAd
                     adView:(__kindof UIView<BaiheAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被关闭
 
 @param nativeExpressAd 广告模板
 */
- (void)Baihe_nativeExpressAdClose:(BaiheAdSDKNativeExpressAd *)nativeExpressAd
                   adView:(__kindof UIView<BaiheAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被展示
 
 @param nativeExpressAd 广告实例
 */
- (void)Baihe_nativeExpressAdExposure:(BaiheAdSDKNativeExpressAd *)nativeExpressAd
                      adView:(__kindof UIView<BaiheAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告展示上报
 
 @param nativeExpressAd 广告实例
 */
- (void)Baihe_nativeExpressAdExposureReport:(BaiheAdSDKNativeExpressAd *)nativeExpressAd
                            adView:(__kindof UIView<BaiheAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告点击上报
 
 @param nativeExpressAd 广告模板
 */
- (void)Baihe_nativeExpressAdClickedReport:(BaiheAdSDKNativeExpressAd *)nativeExpressAd
                           adView:(__kindof UIView<BaiheAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告落地页被关闭
 
 @param nativeExpressAd 广告实例
 */
- (void)Baihe_nativeExpressAdCloseLandingPage:(BaiheAdSDKNativeExpressAd *)nativeExpressAd
                              adView:(__kindof UIView<BaiheAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

@end
